package com.xzz.number;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: hhz
 * @create: 2022-02-15 09:25
 * 1380. 矩阵中的幸运数
 **/
public class LuckyNumbers {
    public static void main(String[] args) {
        System.out.println(luckyNumbers(new int[][]{{3, 7, 8}, {9, 11, 13}, {15, 16, 17}}));
    }

    public static List<Integer> luckyNumbers(int[][] matrix) {
        int m = matrix.length;
        int n = matrix[0].length;
        int[] row = new int[55];
        int[] col = new int[55];

        for (int i = 0; i < m; i++) {
            row[i] = Integer.MAX_VALUE;
            for (int j = 0; j < n; j++) {
                row[i] = Math.min(row[i], matrix[i][j]);
                col[j] = Math.max(col[j], matrix[i][j]);
            }
        }
        List<Integer> res = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                int num = matrix[i][j];
                if (num == col[j] && num == row[i]) {
                    res.add(num);
                }
            }
        }
        return res;
    }
}
